import requests
import csv
with open('688103.csv','a',newline='') as f:
   writer = csv.writer(f)
   writer.writerow(['时间','成交价','手数'])
riqi = '20220409'
#input('输入格式如下:xxxx-')
cookies = {
   'st_sp': f'{riqi}%2014%3A57%3A10',
}
headers = {
    'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 QIHU 360SE'
}
for page in range(27):
   params = (
       ('pagesize', '144'),
       ('ut', '7eea3edcaed734bea9cbfc24409ed989'),
       ('dpt', 'wzfscj'),
       ('cb', 'jQuery1124029337350072397084_1631343037828'),
       ('pageindex', str(page)),
       #('id', '6009051'),
       ('sort', '1'),
       ('ft', '1'),
       ('code', '601390'),
       ('market', '1'),
       ('_', '1631343037827'),
   )
   response = requests.get('http://push2ex.eastmoney.com/getStockFenShi', headers=headers, cookies=cookies,params=params,  verify=True)
   for i in eval(response.text[43:-2])['data']['data']:
       print(i)
       '''
       with open('688103.csv','a',newline='') as f:
           writer = csv.writer(f)
           if len(str(i['t']))<6:
               shi = str(i['t'])[0]
               fen = str(i['t'])[1:3]
               miao = str(i['t'])[3:]
           else:
               shi = str(i['t'])[0:2]
               fen = str(i['t'])[2:4]
               miao = str(i['t'])[4:]
           if i['bs'] == 4:
               a = '--'
           elif i['bs'] == 2:
               a = '买入'
           elif i['bs'] == 1:
               a = '卖出'
       '''